﻿using UnityEngine;
using System.Collections;
using System.Reflection;
using System.Reflection.Extension;
using System.Extension;
using System;

namespace UnityEngine.Extension
{
    public static class Object
    {
        public static void ForEachMemberPath(this UnityEngine.Object source, Action<MemberInfo, string> callBack,params Type[] inclusives)
        {
            if (source is GameObject)
            {

                GameObject gameObject = source as GameObject;
               // gameObject.ForEachMemberInfo(m => callBack(m, m.Name), inclusives);
                gameObject.ForEachComponent<MonoBehaviour>(c => {
                    string path = c.GetType().Name + "/";
                    c.ForEachMemberInfo((m, p) => callBack(m, (path +  p )), inclusives);
                });
            }
            //else
            //    source.ForEachMemberInfo(m => callBack(m, m.Name), inclusives);
        }

        public static bool isNone(this UnityEngine.Object source)
        {
            return source == null;
        }
        public static bool isNotNone(this UnityEngine.Object source)
        {
            return !source.isNone();
        }
    }
}
